package com.tanhua.appserver.controller;

import com.tanhua.appserver.service.CommentsService;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private CommentsService commentsService;

    /**
     * 点开获取评论消息
     * @param movementId
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping
    public ResponseEntity getPage(@RequestParam String movementId,
                                  @RequestParam(defaultValue = "1") int page,
                                  @RequestParam(defaultValue = "10") int pagesize){

        PageResult pr =commentsService.getPage(movementId,page,pagesize);

        return ResponseEntity.ok(pr);

    }

    /**
     * 提交评论
     * @param movementId 动态编号
     *
     * @return 返回null
     */
    @PostMapping
    public ResponseEntity commitComments(@RequestBody Map movementId){
        String id= (String) movementId.get("movementId");
        String comment = (String)movementId.get("comment");
        commentsService.commitComments(id,comment);

        return ResponseEntity.ok(null);
    }

    /**
     * 点击点赞按钮进来
     * @param id
     * @return
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String id){
        Integer counts =commentsService.like(id);
        return ResponseEntity.ok(counts);
    }
    /**
     * 点击点赞按钮进来
     * @param id
     * @return
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity disLike(@PathVariable("id") String id){

        Integer counts =commentsService.disLike(id);
        return ResponseEntity.ok(counts);

    }


}
